import unittest
import time
from ChessBoard import *

class TestEnd2End(unittest.TestCase):
    def setUp(self):
         """ setUp reads and loads moves from data files """
         self.f = open('moves_only_valid.txt', 'r')
         self.chessboard = ChessBoard()
         self.chessboard.resetBoard()                                                     
         self.moves = []                                                                  
         print "Loading moves..."                                                    
         for line in self.f:
            self.moves.extend((line.rstrip()).split(" "))                                
         print "Moves loaded"

    
    def testInitialization(self):
        """ initialization test """
        self.assertTrue(self.chessboard)
        self.assertTrue(self.moves)
        self.assertIsInstance(self.moves,list)

        
    def testGameplay(self):
            """ Attempts to simulate the game loaded from files. When move fails - testcase fails"""
            i = 0
            for move in self.moves:
                print "Move number: ", i
                i += 1
                self.chessboard.printBoard()
                self.assertTrue(self.chessboard.addTextMove(move))
                time.sleep(0.1)

    def tearDown(self):
        """ Cleanup """
        self.chessboard = None
        self.moves = None
        self.f.close()

if __name__ == "__main__":
    unittest.main()

